package com.maybach.core.manager.impl;

import com.maybach.common.model.ShippingOrderDO;
import com.maybach.common.query.ShippingOrderQuery;
import com.maybach.core.dal.mapper.ext.ShippingOrderExtMapper;
import com.maybach.core.manager.ShippingOrderManager;
import com.maybach.util.AssertUtil;
import com.maybach.util.query.support.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * Manager for ShippingOrder.
 */

@Component
public class ShippingOrderManagerImpl implements ShippingOrderManager{
    protected Logger log = LoggerFactory.getLogger(this.getClass());

    
    @Autowired
    protected ShippingOrderExtMapper shippingOrderExtMapper;
    /**
     * query count by query condition.
     */
    @Override
    public int countByQuery(ShippingOrderQuery query){
        return shippingOrderExtMapper.countByQuery(query);
    }

    /**
     * delete by query condition.
     */
    @Override
    public int deleteByQuery(ShippingOrderQuery query){
        return shippingOrderExtMapper.deleteByQuery(query);
    }

    /**
     * delete by primary key.
     */
    @Override
    public int deleteByPrimaryKey(ShippingOrderDO record){
        return shippingOrderExtMapper.deleteByPrimaryKey(record);
    }

    /**
     * insert selective.
     */
    @Override
    public long insertSelective(ShippingOrderDO record){
        return shippingOrderExtMapper.insertSelective(record);
    }

    /**
     * select by query condition.
     */
    @Override
    public List<ShippingOrderDO> selectByQuery(ShippingOrderQuery query){
        return shippingOrderExtMapper.selectByQuery(query);
    }

    /**
     * select by query condition with page.
    */
    @Override
    public PageResult<ShippingOrderDO> selectByQueryWithPage(ShippingOrderQuery query) {
        PageResult<ShippingOrderDO> result = new PageResult<ShippingOrderDO>();
        result.setPageSize(query.getPageSize());
        result.setPageNo(query.getPageNo());
        result.setTotalCount(this.countByQuery(query));
        result.setResult(this.selectByQuery(query));
        return result;
    }

    /**
     * select by primary key.
     */
    @Override
    public ShippingOrderDO selectByPrimaryKey(Long id){
        return shippingOrderExtMapper.selectByPrimaryKey(id);
    }

    @Override
    public ShippingOrderDO selectByOutOrderId(Long outOrderId) {
        AssertUtil.notNull(outOrderId, "outOrderId");
        ShippingOrderQuery query = new ShippingOrderQuery();
        ShippingOrderQuery.Criteria criteria = query.createCriteria();
        criteria.andOuterOrderIdEqualTo(outOrderId);
        List<ShippingOrderDO> shippingOrderDOs = shippingOrderExtMapper.selectByQuery(query);
        if (null != shippingOrderDOs && !shippingOrderDOs.isEmpty()) {
            return shippingOrderDOs.get(0);
        } else {
            return null;
        }
    }

    /**
     * update by query condition selective.
     */
    @Override
    public int updateByQuerySelective( ShippingOrderDO record,  ShippingOrderQuery query){
        return shippingOrderExtMapper.updateByQuerySelective(record,  query);
    }

    /**
     * update by query condition.
     */
    @Override
    public int updateByQuery( ShippingOrderDO record,  ShippingOrderQuery query){

        return shippingOrderExtMapper.updateByQuery(record, query);
    }

    /**
     * update by primary key selective.
     */
    @Override
    public int updateByPrimaryKeySelective(ShippingOrderDO record){
        return shippingOrderExtMapper.updateByPrimaryKeySelective(record);
    }
}